<?php
session_start();
include("../service/specialProductService.php");
include("../service/productService.php");
include("../util/constant.php");
include_once("../util/FTP.php");

$proId = $_POST["product"];
$description = $_POST["description"];
$status = $_POST["status"];
$imgPaths = $_POST["imgPaths"];
$speProId = createSpecialProduct($proId, $description, $status);
 
if($speProId > 0){
    if($status == 1) updateInactiveExcept($speProId);
    
    if(IS_ON_SERVER) FTP::getInstance()->ftpMakeDir(FTP::getInstance()->getServerPath()."product/special/".$speProId, 0777);
    else mkdir("../image/product/special/".$speProId, 0777);
    //$arrayOfImagePath = preg_split("/,/", $imgPaths);
   
//    foreach($arrayOfImagePath as $each){
//        if(createSpecialImage($speProId, $each) == 0){
//         	echo "<script>window.location.href = '../admin/special-product-detail.php?action=".INSERT_FAILED.".1&id=".$speProId."';</script>";
//        }
//    }
    echo "<script>window.location.href = '../admin/special-product-detail.php?action=".INSERT_SUCCESSFULLY."&id=".$speProId."';</script>";
} else{
    echo "<script>window.location.href = '../admin/special-product-detail.php?action=".INSERT_FAILED."';</script>";
}
?>